STRUTS2 의 한글 처리문제 :: 스트럿츠2버젼[SSISO Community]
 
SSISO 카페 SSISO Source SSISO 구직 SSISO 쇼핑몰 SSISO 맛집
추천검색어 : JUnit   Log4j   ajax   spring   struts   struts-config.xml   Synchronized   책정보   Ajax 마스터하기   우측부분

스트럿츠2버젼
[1]
등록일:2008-03-16 12:10:00 (0%)
작성자:
제목:STRUTS2 의 한글 처리문제
기존에 한글처리는 Encoding Filter 를 써서 request의 캐릭터셋을 euc-kr로 변경하였었다.

public void doFilter(ServletRequest request, ServletResponse response,
           FilterChain chain) throws IOException, ServletException {

       if (request.getCharacterEncoding() == null) {
           if (encoding != null) {
               request.setCharacterEncoding(encoding);
               response.setContentType("text/html;charset=" + encoding);
           }
       }
      
       if (chain != null) {
           chain.doFilter(request, response);
       }
   }

struts2를 이용하면서도 이 필터는 잘 되었다.

허나 문제는 Ajax를 이용하여 서버측 액션을 한번 갔다오기만 하면 인코딩 방식이 변경이 된다.

그래서 다음의 필터에 Ajax를 이용하여 액션을 콜하면 위의 필터를 통하지 않겠금 하였다.

한번은 되는데 두번째 부터는 안된다.

위의 chain.doFilter(request, response); 이 부분만 지나면  euc-kr 에서 UTF-8 로 변경이 된다.

한참을 찾아보다 아래의 내용을 적용하고 위의 Encoding Filter를 빼버렸다.

<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<filter>
    <filter-name>struts</filter-name>        
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    <init-param>
        <param-name>struts.i18n.encoding</param-name>  
        <param-value>euc-kr</param-value>
    </init-param>
    <init-param>
        <param-name>struts.devMode</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
</web-app>

바로 한글문제가 해결되었다..ㅠㅠ

몇 시간을 허비했는징..ㅠㅠ

출처 : http://struts.apache.org/2.x/docs/constant-configuration.html
[본문링크] STRUTS2 의 한글 처리문제
[1]
코멘트(이글의 트랙백 주소:/cafe/tb_receive.php?no=2786
작성자
비밀번호

 

SSISOCommunity

[이전]

Copyright byCopyright ⓒ2005, SSISO Community All Rights Reserved.